<template>
  <div class="rightbox" v-cloak>
    <h1>公司中心 > 店铺设置</h1>
    <div class="add-box" style="width:650px;">
      <el-form ref="form" :model="form"  label-width="110px">
        <el-form-item
          prop="case"
          label="选择方案"
          :rules="[
            { required: true, message: '请选择方案', trigger: 'blur' }
          ]"
        >
          <el-select v-model="form.case" multiple placeholder="请选择" style="width:540px">
            <el-option
              v-for="item in form.caseDate"
              :key="item.schemeIndex"
              :label="item.title"
              :value="item.schemeIndex">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          prop="desig"
          label="选择设计师"
          :rules="[
            { required: true, message: '请选择擅长方面', trigger: 'blur' }
          ]"
        >
          <el-select v-model="form.desig" multiple placeholder="请选择" style="width:540px">
            <el-option
              v-for="item in form.desigData"
              :key="item.designerIndex"
              :label="item.name"
              :value="item.designerIndex">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submit('form')">提交</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      form: {
        case: [],
        caseDate: [],
        desig: [],
        desigData: []
      }
    }
  },
  methods: {
    submit: function (form) {
      var that = this
      that.$refs[form].validate((valid) => {
        if (valid) {
          var SchemeView = that.form.case.join(',')
          var DesignerView = that.form.desig.join(',')
          that.$axios.request('post', '/CompanyShop/ReleasePost', {
            SchemeView: SchemeView,
            DesignerView: DesignerView
          })
            .then((res) => {
              if (res.code === 0) {
                that.$pub.messageTwo(res.data, '提示')
              }
            })
        } else {
          return false
        }
      })
    },
    getDate: function () {
      var that = this
      that.$axios.request('post', '/CompanyShop/GetCompanyScheme', {
        Pageindex: 0,
        Pagelimit: 20
      })
        .then((res) => {
          if (res.code === 0) {
            that.form.caseDate = res.data.datalist
          }
        })
      that.$axios.request('post', '/CompanyShop/GetCompanyDesigner', {
        Pageindex: 0,
        Pagelimit: 20
      })
        .then((res) => {
          if (res.code === 0) {
            that.form.desigData = res.data.datalist
          }
        })
      that.$axios.request('post', '/CompanyShop/Index')
        .then((res) => {
          if (res.code === 0) {
            for (var i = 0; i < res.data.designerView.length; i++) {
              that.form.desig.push(res.data.designerView[i].designerIndex)
            }
            for (var n = 0; n < res.data.schemeView.length; n++) {
              that.form.case.push(res.data.schemeView[n].schemeIndex)
            }
          }
        })
    }
  },
  mounted () {
    this.getDate()
  }
}
</script>
